package com.weixinli.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.weixinli.beans.UserGood;
import com.weixinli.dao.IUserGoodDao;

@Repository("iUserGoodDao")
public class UserGoodImpl implements IUserGoodDao {
	@Resource(name="sqlSession")
	private SqlSession sqlSession;
	
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	public int delUserGood(Integer w_uid, Integer area_id) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("w_uid", w_uid);
		map.put("area_id", area_id);
		return sqlSession.delete("userGood.delUserGood",map);
	}

	public int getTotalUserGood() {
		return 0;
	}

	public String findUserGood(Integer w_uid, Integer area_id) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("w_uid", w_uid);
		map.put("area_id", area_id);
		return sqlSession.selectOne("userGood.findUserGood",map);
	}

	public List<UserGood> findOnes(Integer w_uid) {
		return null;
	}

	public int addGood(Integer w_uid, String gid, Integer area_id) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("w_uid", w_uid);
		map.put("gid", gid);
		map.put("area_id", area_id);
		return sqlSession.insert("userGood.addGood", map);
	}
	
	//点赞+1
	public int updateGood(Integer w_uid, String gid, Integer area_id) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("w_uid", w_uid);
		map.put("gid", gid);
		map.put("area_id", area_id);
		return sqlSession.update("userGood.updateGood", map);
	}

}
